import { Controller } from "../../mvc/core/Controller";
import { IGainAwardController } from "./interfaces/IGainAwardController";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SOnlineRewardMsg } from "../../../Message/Game/SOnlineRewardMsg";
import { EOnlineReward } from "../../../Message/Game/EOnlineReward";
import { ServerCommand } from "../mvc/ServerCommand";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
type int = number;
//class GainAwardController
    
    export  class GainAwardController extends Controller implements IGainAwardController
    {
       

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.GainOnlineAward, this.gainOnlineAwardHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateOnlineReward, this.onOnlineAwardHandler);
            return;
        }

        /* internal  */onOnlineAwardHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SOnlineRewardMsg;
            var loc2=new Object();
            loc2.time = loc1.condition;
            loc2.reward = loc1.rewardItems;
            loc2.type = loc1.type;
            if (loc1.type != EOnlineReward._EOnlineRewardNewPlayerReward) 
            {
                if (loc1.type != EOnlineReward._EOnlineRewardDailyReward) 
                {
                    if (loc1.type == EOnlineReward._EOnlineRewardLevelReward1) 
                    {
                        NetDispatcher.dispatchCmd(ServerCommand.LevelAward, loc2);
                    }
                }
                else 
                {
                    NetDispatcher.dispatchCmd(ServerCommand.DailyAward, loc2);
                }
            }
            else 
            {
                NetDispatcher.dispatchCmd(ServerCommand.NewPlayerAward, loc2);
            }
            return;
        }

        /* internal  */gainOnlineAwardHandler(arg1: DataEvent): void
        {
            GameProxy.onlineAwardProxy.gainOnlineAward(arg1.data as int);
            return;
        }
    }
